import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard' }
      }
    ]
  },

  {
    path: '/content',
    component: Layout,
    redirect: '/content/articleList',
    name: 'Content',
    alwaysShow: true,
    meta: { title: '内容管理', icon: 'el-icon-folder-opened' },
    children: [
      {
        path: 'articleList',
        name: 'ArticleList',
        component: () => import('@/views/content/article/index.vue'),
        meta: { title: '文章管理', icon: 'el-icon-tickets' }
      },
      //新增文章
      {
        path: 'addArticle',
        name: 'AddArticle',
        hidden: true,
        component: () => import('@/views/content/article/Detail/index.vue'),
        meta: {
          title: '新增文章',
          icon: 'table',
          activeMenu: '/content/articleList'
        }
      },
      //编辑文章
      {
        path: 'editArticle/:id',
        name: 'EditArticle',
        hidden: true,
        component: () => import('@/views/content/article/Detail/index.vue'),
        meta: {
          title: '编辑文章',
          icon: 'table',
          activeMenu: '/content/articleList'
        }
      },
      //素材管理
      {
        path: 'material',
        name: 'Material',
        component: () => import('@/views/content/material/index.vue'),
        meta: { title: '素材管理', icon: 'el-icon-picture-outline' }
      }
    ]
  },
  {
    path: '/product',
    component: Layout,
    redirect: '/product/productList',
    name: 'product',
    alwaysShow: true,
    meta: { title: '商品管理', icon: 'el-icon-s-shop' },
    children: [
      {
        path: 'productList',
        name: 'productList',
        component: () => import('@/views/product/list'),
        meta: { title: '商品列表', icon: 'el-icon-goods' }
      },
      {
        path: 'classify',
        name: 'classify',
        component: () => import('@/views/product/classify'),
        meta: { title: '商品分类', icon: 'el-icon-menu' }
      },
      {
        path: 'brand',
        name: 'brand',
        component: () => import('@/views/product/brand'),
        meta: { title: '品牌管理', icon: 'el-icon-present' }
      },

      {
        path: 'productDetail',
        name: 'productDetail',
        hidden: true,
        component: () => import('@/views/product/list/Detail'),
        meta: {
          title: '商品详情',
          icon: 'el-icon-goods',
          activeMenu: '/product/productList'
        }
      }
    ]
  },
  {
    path: '/marketing',
    component: Layout,
    redirect: '/marketing/marketingList',
    name: 'marketing',
    alwaysShow: true,
    meta: { title: '营销管理', icon: 'el-icon-goods' },
    children: [
      {
        path: 'marketingList',
        name: 'marketings',
        component: () => import('@/views/marketing'),
        meta: { title: '限时活动', icon: 'el-icon-camera' }
      },
      {
        path: 'advertising',
        name: 'advertising',
        component: () => import('@/views/marketing/advertising'),
        meta: { title: '广告列表', icon: 'el-icon-document-copy' }
      }
    ]
  },
  {
    path: '/registeredUser',
    component: Layout,
    redirect: '/registeredUser/registeredUserList',
    name: 'registeredUser',
    alwaysShow: true,
    meta: { title: '注册用户管理', icon: 'el-icon-user-solid' },
    children: [
      {
        path: 'registeredUserList',
        name: 'registeredUser',
        component: () => import('@/views/registeredUser/index.vue'),
        meta: { title: '用户列表', icon: 'el-icon-user' }
      }
    ]
  },
  {
    path: '/orderFor',
    component: Layout,
    redirect: '/orderFor/orderForList',
    name: 'orderFor',
    alwaysShow: true,
    meta: { title: '订单管理', icon: 'el-icon-tickets' },
    children: [
      {
        path: 'ordergoodsList',
        name: 'ordergoods',
        component: () => import('@/views/orderFor/ordergoods/index.vue'),
        meta: { title: '订单列表', icon: 'el-icon-document-checked' }
      },
      //订单详情
      {
        path: 'detaile/:id',
        name: 'Detaile',
        hidden: true,
        component: () => import('@/views/orderFor/ordergoods/detaile/index.vue'),
        meta: {
          title: '订单详情',
          icon: 'table',
          activeMenu: '/orderFor/detaile'
        }
      },
      {
        path: 'ChargebackList',
        name: 'Chargeback',
        component: () => import('@/views/orderFor/Chargeback/index.vue'),
        meta: { title: '退单列表', icon: 'el-icon-document-delete' }
      },
      {
        path: 'chargebackes/:id',
        name: 'Chargebackes',
        hidden: true,
        component: () => import('@/views/orderFor/Chargeback/chargebackes/index.vue'),
        meta: {
          title: '退单详情',
          icon: 'table',
          activeMenu: '/orderFor/chargebackes'
        }
      },
      {
        path: 'addressList',
        name: 'address',
        component: () => import('@/views/orderFor/address/index.vue'),
        meta: { title: '地址列表', icon: 'el-icon-school' }
      }
    ]
  },
  {
    path: '/authority',
    component: Layout,
    redirect: '/authority/authorityList',
    name: 'authority',
    alwaysShow: true,
    meta: { title: '权限管理', icon: 'el-icon-user' },
    children: [
      {
        path: 'accountNumber',
        name: 'accountNumber',
        component: () => import('@/views/authority/accountNumber/index.vue'),
        meta: { title: '账号管理', icon: 'el-icon-user-solid' }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/authority/role/index.vue'),
        meta: { title: '角色管理', icon: 'el-icon-s-custom' }
      },
      //资源管理
      {
        path: 'naturalResources',
        name: 'naturalResources',
        component: () => import('@/views/authority/naturalResources/index.vue'),
        meta: { title: '资源管理', icon: 'el-icon-s-unfold' }
      }
    ]
  },

  {
    path: '/PersonalCenter',
    component: Layout,
    redirect: '/PersonalCenter/PersonalCenterList',
    name: 'PersonalCenter',
    alwaysShow: true,
    meta: { title: '个人中心', icon: 'el-icon-user-solid' },
    children: [
      {
        path: 'Personalhomepage',
        name: 'Personalhomepage',
        component: () => import('@/views/PersonalCenter/Personalhomepage/index.vue'),
        meta: { title: '个人主页', icon: 'el-icon-user' }
      },
      {
        path: 'Personalsettings',
        name: 'Personalsettings',
        component: () => import('@/views/PersonalCenter/Personalsettings/index.vue'),
        meta: { title: '个人设置', icon: 'el-icon-setting' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
